#if !defined(SORT_BY_CANONICAL_CHROMOSOMES_H)
#define SORT_BY_CANONICAL_CHROMOSOMES_H

#include <string>
#include <boost/regex.hpp>
#include <sort_by_embedded_numbers.h>
namespace
{

	std::string expand_embedded_numbers_canonically(const std::string& orig)
	{

		static boost::regex expand_num_regex("(\\d+)");
		static boost::regex numbers_only_regex("(\\d+)");
		static boost::regex sex_chromosomes_regex("[xyXYwWzZ]");

		if (boost::regex_match(orig, numbers_only_regex))
		{
			return "1 " + regex_replace(orig, expand_num_regex, t_expand_each_number());
		}
		else if (orig.length() == 1)
		{
			if (regex_match(orig, sex_chromosomes_regex))
				return "2 " + orig;
			return "3 " + orig;
		}
		return "4 " + regex_replace(orig, expand_num_regex, t_expand_each_number());
	}
}

struct t_sort_by_canonical_chromosomes
{
	bool operator()(const std::string& a, const std::string& b) const
	{
		return expand_embedded_numbers_canonically(a) < expand_embedded_numbers_canonically(b);
	}
};

#endif
